Package-level declarations

Types

Link copied to clipboard
@Serializable
data class BlobResourceContents(val blob: String, val uri: String, val mimeType: String?) : ResourceContents

Represents the binary contents of a resource encoded as a base64 string.

Link copied to clipboard
@Serializable
data class CallToolRequest(val name: String, val arguments: JsonObject = EmptyJsonObject, val _meta: JsonObject = EmptyJsonObject) : ClientRequest, WithMeta

Used by the client to invoke a tool provided by the server.

Link copied to clipboard
@Serializable
class CallToolResult(val content: List<PromptMessageContent>, val isError: Boolean? = false, val _meta: JsonObject = EmptyJsonObject) : CallToolResultBase

The server's response to a tool call.

Link copied to clipboard
@Serializable
sealed interface CallToolResultBase : ServerResult

The server's response to a tool call.

Link copied to clipboard
@Serializable
data class CancelledNotification(val requestId: RequestId, val reason: String?, val _meta: JsonObject = EmptyJsonObject) : ClientNotification, ServerNotification, WithMeta

This notification can be sent by either side to indicate that it is cancelling a previously issued request.

Link copied to clipboard
@Serializable
data class ClientCapabilities(val experimental: JsonObject? = EmptyJsonObject, val sampling: JsonObject? = EmptyJsonObject, val roots: ClientCapabilities.Roots? = null)

Capabilities a client may support. Known capabilities are defined here, in this, but this is not a closed set: any client can define its own, additional capabilities.

Link copied to clipboard
@Serializable(with = ClientNotificationPolymorphicSerializer::class)
sealed interface ClientNotification : Notification

Represents a notification sent by the client.

Link copied to clipboard

Represents a request sent by the client.

Link copied to clipboard
@Serializable(with = ClientResultPolymorphicSerializer::class)
sealed interface ClientResult : RequestResult

Represents a result returned to the client.

Link copied to clipboard
@Serializable
class CompatibilityCallToolResult(val content: List<PromptMessageContent>, val isError: Boolean? = false, val _meta: JsonObject = EmptyJsonObject, val toolResult: JsonObject = EmptyJsonObject) : CallToolResultBase

CallToolResult extended with backwards compatibility to protocol version 2024-10-07.

Link copied to clipboard
@Serializable
data class CompleteRequest(val ref: Reference, val argument: CompleteRequest.Argument, val _meta: JsonObject = EmptyJsonObject) : ClientRequest, WithMeta

A request from the client to the server to ask for completion options.

Link copied to clipboard
@Serializable
data class CompleteResult(val completion: CompleteResult.Completion, val _meta: JsonObject = EmptyJsonObject) : ServerResult

The server's response to a completion/complete request

Link copied to clipboard
@Serializable
data class CreateMessageRequest(val messages: List<SamplingMessage>, val systemPrompt: String?, val includeContext: CreateMessageRequest.IncludeContext?, val temperature: Double?, val maxTokens: Int, val stopSequences: List<String>?, val metadata: JsonObject = EmptyJsonObject, val modelPreferences: ModelPreferences?, val _meta: JsonObject = EmptyJsonObject) : ServerRequest, WithMeta

A request from the server to sample an LLM via the client. The client has full discretion over which model to select. The client should also inform the user before beginning sampling to allow them to inspect the request (human in the loop) and decide whether to approve it.

Link copied to clipboard
@Serializable
data class CreateMessageResult(val model: String, val stopReason: StopReason? = null, val role: Role, val content: PromptMessageContentTextOrImage, val _meta: JsonObject = EmptyJsonObject) : ClientResult

The client's response to a sampling/create_message request from the server. The client should inform the user before returning the sampled message to allow them to inspect the response (human in the loop) and decide whether to allow the server to see it.

Link copied to clipboard
typealias Cursor = String

An opaque token used to represent a cursor for pagination.

Link copied to clipboard
@Serializable
class CustomMeta(val _meta: JsonObject = EmptyJsonObject) : WithMeta

An implementation of WithMeta containing custom metadata.

Link copied to clipboard
@Serializable
open class CustomRequest(val method: Method) : Request

A custom request with a specified method.

Link copied to clipboard
@Serializable
data class EmbeddedResource(val resource: ResourceContents) : PromptMessageContent

The contents of a resource, embedded into a prompt or tool call result.

Link copied to clipboard
@Serializable
data class EmptyRequestResult(val _meta: JsonObject = EmptyJsonObject) : ServerResult, ClientResult

An empty result for a request, containing optional metadata.

Link copied to clipboard
@Serializable(with = ErrorCodeSerializer::class)
sealed interface ErrorCode

An incomplete set of error codes that may appear in JSON-RPC responses.

Link copied to clipboard
@Serializable
data class GetPromptRequest(val name: String, val arguments: Map<String, String>?, val _meta: JsonObject = EmptyJsonObject) : ClientRequest, WithMeta

Used by the client to get a prompt provided by the server.

Link copied to clipboard
@Serializable
class GetPromptResult(val description: String?, val messages: List<PromptMessage>, val _meta: JsonObject = EmptyJsonObject) : ServerResult

The server's response to a prompts/get request from the client.

Link copied to clipboard
@Serializable
data class ImageContent(val data: String, val mimeType: String) : PromptMessageContentTextOrImage

An image provided to or from an LLM.

Link copied to clipboard
@Serializable
data class Implementation(val name: String, val version: String)

Describes the name and version of an MCP implementation.

Link copied to clipboard

This notification is sent from the client to the server after initialization has finished.

Link copied to clipboard
@Serializable
data class InitializeRequest(val protocolVersion: String, val capabilities: ClientCapabilities, val clientInfo: Implementation, val _meta: JsonObject = EmptyJsonObject) : ClientRequest, WithMeta

This request is sent from the client to the server when it first connects, asking it to begin initialization.

Link copied to clipboard
@Serializable
data class InitializeResult(val protocolVersion: String = LATEST_PROTOCOL_VERSION, val capabilities: ServerCapabilities = ServerCapabilities(), val serverInfo: Implementation, val _meta: JsonObject = EmptyJsonObject) : ServerResult

After receiving an initialized request from the client, the server sends this response.

Link copied to clipboard
@Serializable
data class JSONRPCError(val code: ErrorCode, val message: String, val data: JsonObject = EmptyJsonObject) : JSONRPCMessage

A response to a request that indicates an error occurred.

Link copied to clipboard
@Serializable(with = JSONRPCMessagePolymorphicSerializer::class)
sealed interface JSONRPCMessage

Represents a JSON-RPC message in the protocol.

Link copied to clipboard
@Serializable
data class JSONRPCNotification(val method: String, val params: JsonElement = EmptyJsonObject, val jsonrpc: String = JSONRPC_VERSION) : JSONRPCMessage

A notification which does not expect a response.

Link copied to clipboard
@Serializable
data class JSONRPCRequest(val id: RequestId = REQUEST_MESSAGE_ID.incrementAndGet(), val method: String, val params: JsonElement? = null, val jsonrpc: String = JSONRPC_VERSION) : JSONRPCMessage

A request that expects a response.

Link copied to clipboard
@Serializable
class JSONRPCResponse(val id: RequestId, val jsonrpc: String = JSONRPC_VERSION, val result: RequestResult? = null, val error: JSONRPCError? = null) : JSONRPCMessage

A successful (non-error) response to a request.

Link copied to clipboard
@Serializable
data class ListPromptsRequest(val cursor: Cursor? = null, val _meta: JsonObject = EmptyJsonObject) : ClientRequest, PaginatedRequest

Sent from the client to request a list of prompts and prompt templates the server has.

Link copied to clipboard
@Serializable
class ListPromptsResult(val prompts: List<Prompt>, val nextCursor: Cursor? = null, val _meta: JsonObject = EmptyJsonObject) : ServerResult, PaginatedResult

The server's response to a prompts/list request from the client.

Link copied to clipboard
@Serializable
data class ListResourcesRequest(val cursor: Cursor? = null, val _meta: JsonObject = EmptyJsonObject) : ClientRequest, PaginatedRequest

Sent from the client to request a list of resources the server has.

Link copied to clipboard
@Serializable
class ListResourcesResult(val resources: List<Resource>, val nextCursor: Cursor? = null, val _meta: JsonObject = EmptyJsonObject) : ServerResult, PaginatedResult

The server's response to a resources/list request from the client.

Link copied to clipboard
@Serializable
data class ListResourceTemplatesRequest(val cursor: Cursor?, val _meta: JsonObject = EmptyJsonObject) : ClientRequest, PaginatedRequest

Sent from the client to request a list of resource templates the server has.

Link copied to clipboard
@Serializable
class ListResourceTemplatesResult(val resourceTemplates: List<ResourceTemplate>, val nextCursor: Cursor? = null, val _meta: JsonObject = EmptyJsonObject) : ServerResult, PaginatedResult

The server's response to a resources/templates/list request from the client.

Link copied to clipboard
@Serializable
class ListRootsRequest(val _meta: JsonObject = EmptyJsonObject) : ServerRequest, WithMeta

Sent from the server to request a list of root URIs from the client.

Link copied to clipboard
@Serializable
class ListRootsResult(val roots: List<Root>, val _meta: JsonObject = EmptyJsonObject) : ClientResult

The client's response to a roots/list request from the server.

Link copied to clipboard
@Serializable
data class ListToolsRequest(val cursor: Cursor? = null, val _meta: JsonObject = EmptyJsonObject) : ClientRequest, PaginatedRequest

Sent from the client to request a list of tools the server has.

Link copied to clipboard
@Serializable
class ListToolsResult(val tools: List<Tool>, val nextCursor: Cursor?, val _meta: JsonObject = EmptyJsonObject) : ServerResult, PaginatedResult

The server's response to a tools/list request from the client.

Link copied to clipboard
@Serializable
enum LoggingLevel : Enum<LoggingLevel>

The severity of a log message.

Link copied to clipboard
@Serializable
data class LoggingMessageNotification(val level: LoggingLevel, val logger: String? = null, val data: JsonObject = EmptyJsonObject, val _meta: JsonObject = EmptyJsonObject) : ServerNotification, WithMeta

org.jetbrains.kotlinx.mcp.Notification of a log message passed from server to client. If no logging level request has been sent from the client, the server MAY decide which messages to send automatically.

Link copied to clipboard
class McpError(val code: Int, message: String, val data: JsonObject = EmptyJsonObject) : Exception

Represents an error specific to the MCP protocol.

Link copied to clipboard
@Serializable(with = RequestMethodSerializer::class)
sealed interface Method

Represents a method in the protocol, which can be predefined or custom.

Link copied to clipboard
@Serializable
data class ModelHint(val name: String?)

Hints to use for model selection.

Link copied to clipboard
@Serializable
class ModelPreferences(val hints: List<ModelHint>?, val costPriority: Double?, val speedPriority: Double?, val intelligencePriority: Double?)

The server's preferences for model selection, requested by the client during sampling.

Link copied to clipboard
@Serializable(with = NotificationPolymorphicSerializer::class)
sealed interface Notification

Represents a notification in the protocol.

Link copied to clipboard
@Serializable
sealed interface PaginatedRequest : Request, WithMeta

Represents a request supporting pagination.

Link copied to clipboard
@Serializable
sealed interface PaginatedResult : RequestResult

Represents a paginated result of a request.

Link copied to clipboard

A ping, issued by either the server or the client, to check that the other party is still alive. The receiver must promptly respond, or else may be disconnected.

Link copied to clipboard
@Serializable
open class Progress(val progress: Int, val total: Double?) : ProgressBase

Represents a progress notification.

Link copied to clipboard
@Serializable
sealed interface ProgressBase

Represents the base interface for progress tracking.

Link copied to clipboard
@Serializable
data class ProgressNotification(val progress: Int, val progressToken: ProgressToken, val _meta: JsonObject = EmptyJsonObject, val total: Double?) : ClientNotification, ServerNotification, ProgressBase

An out-of-band notification used to inform the receiver of a progress update for a long-running request.

Link copied to clipboard
typealias ProgressToken = Long

A progress token, used to associate progress notifications with the original request. Stores message ID.

Link copied to clipboard
@Serializable
class Prompt(val name: String, val description: String?, val arguments: List<PromptArgument>?)

A prompt or prompt template that the server offers.

Link copied to clipboard
@Serializable
data class PromptArgument(val name: String, val description: String?, val required: Boolean?)

Describes an argument that a prompt can accept.

Link copied to clipboard

An optional notification from the server to the client, informing it that the list of prompts it offers has changed. Servers may issue this without any previous subscription from the client.

Link copied to clipboard
@Serializable
data class PromptMessage(val role: Role, val content: PromptMessageContent)

Describes a message returned as part of a prompt.

Link copied to clipboard
@Serializable(with = PromptMessageContentPolymorphicSerializer::class)
sealed interface PromptMessageContent

Represents the content of a prompt message.

Link copied to clipboard
@Serializable(with = PromptMessageContentTextOrImagePolymorphicSerializer::class)
sealed interface PromptMessageContentTextOrImage : PromptMessageContent

Represents prompt message content that is either text or an image.

Link copied to clipboard
@Serializable
data class PromptReference(val name: String) : Reference

Identifies a prompt.

Link copied to clipboard
@Serializable
data class ReadResourceRequest(val uri: String, val _meta: JsonObject = EmptyJsonObject) : ClientRequest, WithMeta

Sent from the client to the server to read a specific resource URI.

Link copied to clipboard
@Serializable
class ReadResourceResult(val contents: List<ResourceContents>, val _meta: JsonObject = EmptyJsonObject) : ServerResult

The server's response to a resources/read request from the client.

Link copied to clipboard
@Serializable(with = ReferencePolymorphicSerializer::class)
sealed interface Reference
Link copied to clipboard
@Serializable(with = RequestPolymorphicSerializer::class)
sealed interface Request

Represents a request in the protocol.

Link copied to clipboard
typealias RequestId = Long

A uniquely identifying ID for a request in JSON-RPC.

Link copied to clipboard
@Serializable(with = RequestResultPolymorphicSerializer::class)
sealed interface RequestResult : WithMeta

Represents the result of a request, including additional metadata.

Link copied to clipboard
@Serializable
data class Resource(val uri: String, val name: String, val description: String?, val mimeType: String?)

A known resource that the server is capable of reading.

Link copied to clipboard
@Serializable(with = ResourceContentsPolymorphicSerializer::class)
sealed interface ResourceContents

The contents of a specific resource or sub-resource.

Link copied to clipboard

An optional notification from the server to the client, informing it that the list of resources it can read from has changed. Servers may issue this without any previous subscription from the client.

Link copied to clipboard
@Serializable
data class ResourceReference(val uri: String) : Reference

A reference to a resource or resource template definition.

Link copied to clipboard
@Serializable
data class ResourceTemplate(val uriTemplate: String, val name: String, val description: String?, val mimeType: String?)

A template description for resources available on the server.

Link copied to clipboard
@Serializable
data class ResourceUpdatedNotification(val uri: String, val _meta: JsonObject = EmptyJsonObject) : ServerNotification, WithMeta

A notification from the server to the client, informing it that a resource has changed and may need to be read again. This should only be sent if the client previously sent a resources/subscribe request.

Link copied to clipboard
@Serializable
enum Role : Enum<Role>

Enum representing the role of a participant.

Link copied to clipboard
@Serializable
data class Root(val uri: String, val name: String?)

Represents a root directory or file that the server can operate on.

Link copied to clipboard

A notification from the client to the server, informing it that the list of roots has changed.

Link copied to clipboard
@Serializable
data class SamplingMessage(val role: Role, val content: PromptMessageContentTextOrImage)

Describes a message issued to or received from an LLM API.

Link copied to clipboard
@Serializable
data class ServerCapabilities(val experimental: JsonObject? = EmptyJsonObject, val sampling: JsonObject? = EmptyJsonObject, val logging: JsonObject? = EmptyJsonObject, val prompts: ServerCapabilities.Prompts? = null, val resources: ServerCapabilities.Resources? = null, val tools: ServerCapabilities.Tools? = null)

Represents the capabilities that a server can support.

Link copied to clipboard
@Serializable(with = ServerNotificationPolymorphicSerializer::class)
sealed interface ServerNotification : Notification

Represents a notification sent by the server.

Link copied to clipboard
sealed interface ServerRequest : Request

Represents a request sent by the server.

Link copied to clipboard
@Serializable(with = ServerResultPolymorphicSerializer::class)
sealed interface ServerResult : RequestResult

Represents a result returned by the server.

Link copied to clipboard
@Serializable(with = StopReasonSerializer::class)
sealed interface StopReason
Link copied to clipboard
@Serializable
data class SubscribeRequest(val uri: String, val _meta: JsonObject = EmptyJsonObject) : ClientRequest, WithMeta

Sent from the client to request resources/updated notifications from the server whenever a particular resource changes.

Link copied to clipboard
@Serializable
data class TextContent(val text: String? = null) : PromptMessageContentTextOrImage

Text provided to or from an LLM.

Link copied to clipboard
@Serializable
data class TextResourceContents(val text: String, val uri: String, val mimeType: String?) : ResourceContents

Represents the text contents of a resource.

Link copied to clipboard
@Serializable
data class Tool(val name: String, val description: String?, val inputSchema: Tool.Input)

Definition for a tool the client can call.

Link copied to clipboard

An optional notification from the server to the client, informing it that the list of tools it offers has changed. Servers may issue this without any previous subscription from the client.

Link copied to clipboard
@Serializable
data class UnknownContent(val type: String) : PromptMessageContentTextOrImage

An image provided to or from an LLM.

Link copied to clipboard

Represents a request or notification for an unknown method.

Link copied to clipboard
@Serializable
data class UnknownReference(val type: String) : Reference

Identifies a prompt.

Link copied to clipboard
@Serializable
data class UnknownResourceContents(val uri: String, val mimeType: String?) : ResourceContents

Represents resource contents with unknown or unspecified data.

Link copied to clipboard
@Serializable
data class UnsubscribeRequest(val uri: String, val _meta: JsonObject = EmptyJsonObject) : ClientRequest, WithMeta

Sent from the client to request cancellation of resources/updated notifications from the server. This should follow a previous resources/subscribe request.

Link copied to clipboard
@Serializable
sealed interface WithMeta

Represents an entity that includes additional metadata in its responses.

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard

Decodes a JSON-RPC notification into a protocol-specific Notification.

Decodes a JSON-RPC request into a protocol-specific Request.

Link copied to clipboard

Converts the notification to a JSON-RPC notification.

Converts the request to a JSON-RPC request.